﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using OgilvyOne.IDAL;
using OgilvyOne.Model;

namespace OgilvyOne.SqlServerDAL
{
    public class CmsColumnMores : ICmsColumnMores
    {
        private const string LAYERID_GET_MORES_SQL = "SELECT [COLUMN_MORES_ID],[LAYERID],[MORES_NAME],[MORES_ENAME],[MORES_TYPE],[ROWS],[COLS],[MAXLENGTH]  FROM [CMS_COLUMN_MORES] WHERE '{0}'  LIKE '%'+LAYERID+'%' order by COLUMN_MORES_ID";

        public IList GetColumnMoresList(string layerid)
        {
            
            SqlParameter[] parms = new SqlParameter[] {
               // new SqlParameter("@LAYERID", SqlDbType.VarChar)
            };
            //parms[0].Value = layerid;

            IList datalist = new ArrayList();
            using (SqlDataReader rdr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, string.Format(LAYERID_GET_MORES_SQL, layerid), parms))
            {
                while (rdr.Read())
                {
                    CmsColumnMoresModel ccm = new CmsColumnMoresModel();
                    ccm.Column_mores_id = rdr.GetInt32(0);
                    ccm.Layerid = rdr.GetString(1);
                    ccm.Mores_name = rdr.GetString(2);
                    ccm.Mores_ename = rdr.GetString(3);
                    ccm.Mores_type = rdr.GetString(4);
                    if (!rdr.IsDBNull(5)) ccm.Rows = rdr.GetInt32(5);
                    if (!rdr.IsDBNull(6)) ccm.Cols = rdr.GetInt32(6);
                    if (!rdr.IsDBNull(7)) ccm.Maxlength = rdr.GetInt32(7);

                    datalist.Add(ccm);

                }
            }
            return datalist;
        }
    }
}
